package com.itcast.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itcast.entity.PageResult;
import com.itcast.entity.QueryPageBean;
import com.itcast.mapper.CheckitemMapper;
import com.itcast.pojo.CheckItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = CheckitemService.class)
@Transactional
public class CheckitemServiceImpl implements CheckitemService{
    @Autowired
    private CheckitemMapper checkitemMapper;

    /**
     * 添加数据
     * @param checkItem
     */
    @Override
    public void add(CheckItem checkItem) {
        checkitemMapper.add(checkItem);
    }

    /**
     * 查询数据
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult findAll(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        PageHelper.startPage(currentPage,pageSize);
        Page<CheckItem> checkItems = checkitemMapper.findAll(queryString);
        return new PageResult(checkItems.getTotal(),checkItems.getResult());
    }

    /**
     * 删除数据
     * @param id
     */
    @Override
    public void delete(int id) {
        checkitemMapper.delete(id);
    }

    /**
     * 查询编辑项实现回显
     * @param id
     */
    @Override
    public CheckItem findByid(Integer id) {
        return checkitemMapper.findByid(id);
    }

    /**
     * 修改数据
     * @param checkItem
     */
    @Override
    public void update(CheckItem checkItem) {
        checkitemMapper.update(checkItem);
    }

    @Override
    public List<CheckItem> findall() {
        return checkitemMapper.findall();
    }
}
